package ar.com.sne.model.composer.dom;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.api.Textbox;

import foundation.common.util.CommonWebUtil;
import foundation.common.util.FinderFilter;
import foundation.common.util.PagedFinder;
import foundation.web.flow.AbstractPagingComposer;
import ar.com.sne.bean.BaseBO;
import ar.com.sne.model.bo.dom.DomMercaderia;
import ar.com.sne.model.enumeration.dom.TipoMercaderia;
import ar.com.sne.model.service.dom.DomMercaderiaService;
import coop.tecso.foundation.common.macros.ComboBoxEnum;


@Service
@Scope("prototype")
public class AdministracionMercaderiaComposer  extends
AbstractPagingComposer {
	
	private final Log log = LogFactory.getLog(getClass());
	
	public Textbox tboxNombre;
	public Datebox dboxCosecha;
	public ComboBoxEnum cbbTipoMercaderia;
	
	@Resource
	private DomMercaderiaService domMercaderiaService;
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		// TODO Auto-generated method stub
		super.doAfterCompose(comp);
	}
	
	
	@Override
	protected PagedFinder searchPaging(PagedFinder pf) {
		return domMercaderiaService.findPaging(pf);
	}
	
	
	@Override
	protected FinderFilter setterFilters() {
		FinderFilter filter = new FinderFilter();
		filter.addFilter("fechaCosecha",  dboxCosecha.getValue());
		filter.addFilter("nombre",  tboxNombre.getValue());
		if (cbbTipoMercaderia.getSelectedIndex() > 0)
			filter.addFilter("tipoMercaderia",  cbbTipoMercaderia.getObjectSelect());

		return filter;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @seecoop.foundation.zk.crud.composer.AbstractCRUDManagerComposer#
	 * getEditPageName()
	 */
	protected String getEditPageName() {
		return "edicionMercaderia";
	}

	public Object[] getTipoMercaderiaList(){
		return TipoMercaderia.values();
	}
	
	@Override
	protected void deleteObject(BaseBO objectToDelete) {
		domMercaderiaService.delete((DomMercaderia) objectToDelete);
	}

	
	/*
	 * (non-Javadoc)
	 * 
	 * @seecoop.foundation.zk.crud.composer.AbstractCRUDManagerComposer#
	 * clearFilterCriteriaFields()
	 */
	@Override
	protected void clearFilterCriteriaFields() {
		tboxNombre.setValue(null);
		dboxCosecha.setValue(null);
		cbbTipoMercaderia.setValue(CommonWebUtil.getProperty("combobox.value.todos"));
	}


	public DomMercaderiaService getDomMercaderiaService() {
		return domMercaderiaService;
	}


	public void setDomMercaderiaService(DomMercaderiaService domMercaderiaService) {
		this.domMercaderiaService = domMercaderiaService;
	}


	
}
